// 	ID : pallab81
// 	PROG : 10285
// 	LANG : C++
// 	2011-08-14-10.13.46 Sunday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ) {
    double endtime = clock() + ( seconds+ CLOCKS_PER_SEC );
    while( clock() < endtime ) {
        ;
    }
}
string _name;
int R,C;
int grid[ 110 ][ 110 ];
int cando[ 110 ][ 110 ];
int move[4][2] = { {-1,0},{+1,0},{0,-1},{0,+1} } ;

inline void Read() {
    cin>>_name;
    CI(R);
    CI(C);
    fo(i,R) {
        fo(j,C) {
            CI( grid[i][j] );
        }
    }
}
inline int go(int r, int c) {
    if( r<0 || c<0 ) {
        return 0;
    }
    int &best = cando[r][c];
    if( best!= -1 ) {
        return best;
    }
    best = 0;
    fo(i,4) {
        int tr = r+ move[i][0];
        int tc = c+ move[i][1];
        if( tr < 0 || tr >=R || tc < 0 || tc >=C )continue;
        if( grid[ tr ][ tc ] < grid[r][c] ) {
            int a = 1+go( tr, tc );
            best = max( best, a );
        }
    }

    return best;
}

inline void Proc() {
    SET( cando, -1 );
    fo(i,R) {
        fo(j,C) {
            go(i,j);
        }
    }
    int retval = 0;
    fo(_i,R) {
        fo(_j,C) {
            retval = max( retval , cando[_i][_j] );
            //printf("%3d", cando[_i][_j]);
        }
        //printf("\n");
    }
    printf("%s: %d\n",_name.c_str(),retval+1);
    // wait(.3);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
#endif

    int cases;
    for( CI(cases) ; cases ; --cases ) {
        Read();
        Proc();
    }
    return 0;
}
